#include "reg.h"
#include "ui_reg.h"
#include<QTimer>
#include<QTimerEvent>
#include<QCloseEvent>
#include<QPushButton>

reg::reg(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::reg)
{
    ui->setupUi(this);
    setMouseTracking(true);
    this->startTimer(5000);
    ui->regok->setDown(true);


}

reg::~reg()
{
    delete ui;
}
void reg::timerEvent(QTimerEvent *){
    static int i=0;
    ui->stackedWidget->setCurrentIndex((i++)%3);
}
void reg::closeEvent(QCloseEvent *){
    emit cancle();
}




void reg::on_regok_clicked()
{
    QString str1=ui->dewnname->text();
    QString str2=ui->account->text();
    QString str3=ui->password->text();
    QString str4=ui->phonenum->text();
    ui->dewnname->clear();
    ui->account->clear();
    ui->password->clear();
    ui->phonenum->clear();
    if(str1.isEmpty()==false&&str2.isEmpty()==false
            &&str3.isEmpty()==false&&str4.isEmpty()==false
            &&ui->check->checkState()==Qt::Checked){

        emit regok(str1,str2,str3,str4);
        this->close();
    }
    else{
        if(ui->check->checkState()==Qt::Unchecked){
            ui->checkremind->setText("请认真阅读并勾选下方协议");
        }
        else{
            ui->checkremind->setText("");
        }
        if(str1.isEmpty()==true){
            ui->nameremind->setText("昵称不能为空");
        }
        else{
            ui->nameremind->setText("");
        }
        if(str2.isEmpty()==true){
            ui->accountremind->setText("账号不能为空");
        }
        else{
           ui->accountremind->setText("");
        }
        if(str3.isEmpty()==true){
            ui->passwordremind->setText("密码不能为空");
        }
        else{
            ui->passwordremind->setText("");
        }
        if(str4.isEmpty()==true){
            ui->phonumremind->setText("手机号不能为空");
        }
        else{
            ui->phonumremind->setText("");
        }
        return;
    }
}
